package com.liyao.windowtest4.Utils;

import java.io.*;
import java.util.Properties;

/**
 * @program: windowtest3
 * @description:
 * @author: liu yan
 * @create: 2024-10-14 15:17
 */
public class PasswordConfig {
    private static final String CONFIG_FILE = "application.properties";
    private static Properties properties = new Properties();

    static {
        String projectDir = System.getProperty("user.dir");
//        try (InputStream input = PasswordConfig.class.getClassLoader().getResourceAsStream(projectDir+ File.separator +"config"+File.separator +CONFIG_FILE)) {
        try (InputStream input = new FileInputStream(projectDir+ File.separator +"config"+File.separator +CONFIG_FILE)) {
            // 检查输入流是否为空，以防文件未找到
            if (input == null) {
                System.out.println("Sorry, unable to find config.properties");
            }
            // 从输入流加载属性
            properties.load(input);

            // 示例：获取一个属性
            String someProperty = properties.getProperty("correct.password");
            System.out.println("Property value: " + someProperty);

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }



    public static String getCorrectPassword() {
        return properties.getProperty("correct.password");
    }
}
